#!/usr/bin/ruby

require 'rubygems'
require 'yaml'
require 'erb'

['build', 'cs_final', 'cs_src'].each { |dirname| Dir.mkdir(dirname) unless File.exist?(dirname) }

cs_template = ERB.new <<EOF
namespace Hero {
  class ErrorCode {
    <% @error_code.each do |k, v| %>
      public const int <%= v.swapcase.tr('.', '_') %> = <%= k %>;
    <%end%>
  }
}
EOF

@error_code = []
DATA.read.split("\n").each do |line| 
  line.strip!
  if line != '' 
    @error_code << [line.split(": ")[0], line.split(": ")[1]]
  end
end

puts __FILE__
File.open(File.expand_path("../build/error_code.json", __FILE__), "w") do |f|
  f << "{\n"
  f << @error_code.sort_by{|arr| arr[1] }.map { |v, k| "\t\"#{k}\": #{v}"}.join(",\n")
  f << "\n}"
end

#File.open(File.expand_path("../cs_final/error_code.cs", __FILE__), "w") do |f|
#  f << cs_template.result(binding)
#end

__END__
101000: ui.exceed.max.hero
101001: ui.package.not.enough.gem
101002: ui.package.confirm.enlarge
101003: ui.pvp.win
101100: ui.title.warn
102001: btn.enlarge.package
102002: btn.clean.package
103001: btn.cancel
103002: btn.ok
103003: btn.cost.gem
103004: btn.raid.cost.tili

104001: newbie.message.title
104002: newbie.message.gonghui
104003: newbie.message.pvp
104100: social.brocast.inventory.compound
104101: social.brocast.inventory.gain
104102: social.brocast.hero.compound
104103: social.brocast.hero.gain
104110: pve.energy.not.enough

1001: version.not.supported
11000: account.login.failed
11001: account.has.locked
11010: account.loginbyemail.email.not.exists
11011: account.loginbyemail.wrong.password
11020: account.register.mail.exists
11021: account.register.token.wrong
11030: account.binding.mail.exists
11040: account.modify.worong.oldpassword
11050: account.retreive.mail.not.exists
11060: account.verifytoken.wrong.token
12000: userinfo.setname.check.not.legal
12001: userinfo.setname.platform.ngkeyword.not.exist
12010: userinfo.enlargeheromaxnum.wrong.curmax
12011: userinfo.enlargeheromaxnum.gem.not.enough
12020: userinfo.enlargeequipmaxnum.wrong.curmax
12021: userinfo.enlargeequipmaxnum.gem.not.enough
12030: userinfo.buyenergy.wrong.param
12031: userinfo.buyenergy.exceed.limit
12032: userinfo.buyenergy.gem.not.enough
12040: userinfo.buyenergypvp.wrong.param
12041: userinfo.buyenergypvp.exceed.limit
12042: userinfo.buyenergypvp.gem.not.enough
13000: hero.inithero.already.has.hero
13010: hero.eathero.no.such.hero
13011: hero.eathero.max.qianghua.limit
13012: hero.eathero.gold.not.enough
13013: hero.eathero.hero.locked
13014: hero.eathero.hero.not.qualified
13020: hero.combinehero.no.such.hero
13021: hero.combinehero.not.max.level
13022: hero.combinehero.hero.locked
13023: hero.combinehero.not.max.qianghua
13024: hero.combinehero.level.not.equal
13025: hero.combinehero.qianghua.not.equal
13026: hero.combinehero.star.not.equal
13027: hero.combinehero.star.max
13030: hero.changelineup.cannot.remove.zero
13031: hero.changelineup.wrong.param
13040: hero.lock.no.such.hero
13050: hero.sell.no.such.hero
13051: hero.sell.hero.locked
13060: hero.id.not.exist
14000: pve.map.id.wrong
14010: pve.start.gold.not.enough
14011: pve.start.energy.not.enough
14012: pve.start.friend.not.exist
14013: pve.start.not.friend
14014: pve.start.friend.already.assisted
14015: pve.start.mapid.not.open
14020: pve.finish.cheat
14030: pve.buylife.gem.not.enough
14040: pve.buyaward.gem.not.enough
14041: pve.buyaward.map.not.exist
14042: pve.buyaward.award.not.exist
15001: pvp.start.target.not.exist
15002: pvp.start.energypvp.not.enough
15003: pvp.start.gold.not.enough
15010: pvp.finish.target.not.exist
15011: pvp.finish.target.not.equal
15012: pvp.finish.not.start
15020: pvp.getaward.award.cannot.take
15021: pvp.getaward.award.already.take
16000: social.addfriend.username.not.exist
16001: social.addfriend.userid.not.exist
16002: social.addfriend.userid.already.added
16010: social.acceptfriendrequest.userid.not.exist
16020: social.delfriend.userid.not.exist
16030: social.getfriendinfo.userid.not.exist
16040: social.sendfriend.not.friend
16041: social.sendfriend.already.sent
16050: social.addmaster.userid.not.exist
16051: social.addmaster.already.master
16052: social.addmaster.student.cannot.be.master
17003: gang.create.gold.not.enough
17001: gang.create.already.has.gang
17002: gang.create.name.exist
17010: gang.join.gangid.not.exist
17011: gang.join.already.has.gang
17020: gang.changememberauth.not.in.gang
17021: gang.changememberauth.no.such.auth
17022: gang.changememberauth.userid.not.exist
17030: gang.dismiss.not.in.gang
17031: gang.dismiss.no.such.auth
17040: gang.changeinfo.not.in.gang
17041: gang.changeinfo.no.such.auth
17050: gang.invitemember.not.in.gang
17051: gang.invitemember.no.such.auth
17052: gang.invitemember.userid.in.gang
17053: gang.invitemember.gang.is.full
17060: gang.kickmember.not.in.gang
17061: gang.kickmember.no.such.auth
17070: gang.acceptinvite.already.has.gang
17071: gang.acceptinvite.gangid.not.exist
17072: gang.acceptinvite.gang.is.full
17080: gang.bidforauction.wrong.param
17090: gang.quitgang.not.in.gang
17091: gang.quitgang.creator.cannot.quit
17100: gang.getganginvitedfriendids.not.in.gang
17101: gang.getganginvitedfriendids.no.such.auth
18000: activity.collectmail.no.such.mail
19000: task.takeachievementaward.id.not.exist
19001: task.takeachievementaward.already.take
19002: task.takeachievementaward.not.finish
20000: equip.equiphero.no.such.hero
20001: equip.equiphero.no.such.equip
20010: equip.sellequip.no.such.equip
30000: gem.not.enough
30001: gold.not.enough
30003: contribution.not.enough
